package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.ResponseResult;
import com.web.entity.User;
import com.web.service.UserService;
import com.web.service.impl.UserServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateUser")
public class UpdateUserServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得参数
        String sid=req.getParameter("id");
        String nickname=req.getParameter("nickname");
        String icon=req.getParameter("icon");
        String email=req.getParameter("email");
        int id=0;
        if(sid!=null){
            id=Integer.parseInt(sid);
        }
        //更新用户信息
        UserService userService=new UserServiceimpl();
        User user=new User();
        user.setId(id);
        user.setNickname(nickname);
        user.setIcon(icon);
        user.setEmail(email);
        userService.updateUser(user);
        //返回信息给前端
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"ok",null)));
    }
}
